class <%= controller_class_name %>Controller < ApplicationController

  layout 'application'

<% unless suffix -%>
  def index
    listar<%= controller_class_name %>
    render :action => 'listar<%= controller_class_name %>'
  end
<% end -%>

<% for action in unscaffolded_actions -%>
  def <%= action %><%= controller_class_name %><%= suffix %>
  end

<% end -%>
  def listar<%= controller_class_name %><%= suffix %>
    @<%= singular_name %>_pages, @<%= plural_name %> = paginate :<%= plural_name %>, :per_page => 30
  end

  def novo<%= controller_class_name %><%= suffix %>
    @page = params[:page]
    @<%= singular_name %> = <%= model_name %>.new
  end

  def inserir<%= controller_class_name %><%= suffix %>
    @page = params[:page]
    @<%= singular_name %> = <%= model_name %>.new(params[:<%= singular_name %>])
    
    if @<%= singular_name %>.save
      redirect_to :action => 'listar<%= controller_class_name %><%= suffix %>', :page => @page
    else
      render :action => "novo<%= controller_class_name %>"
    end
  end

  def editar<%= controller_class_name %><%= suffix %> 
    @page = params[:page]
    @<%= singular_name %> = <%= model_name %>.find(params[:id])
  end

  def atualizar<%= controller_class_name %>
    @page = params[:page]
    @<%= singular_name %> = <%= model_name %>.find(params[:id])
    if @<%= singular_name %>.update_attributes(params[:<%= singular_name %>])
      flash[:notice] = '<%= model_name %> foi editado com sucesso.'
      redirect_to :action => 'ver<%= controller_class_name %><%= suffix %>', :id => @<%= singular_name %>, :page => @page
    else
      render :action => 'editar<%= controller_class_name %><%= suffix %>'
    end
  end

  def ver<%= controller_class_name %>
    @page = params[:page]
    @<%= singular_name %> = <%= model_name %>.find(params[:id])
  end

  def apagar<%= controller_class_name %><%= suffix %>
    @page = params[:page]
    <%= model_name %>.find(params[:id]).destroy
    redirect_to :action => 'listar<%= controller_class_name %><%= suffix %>', :page => @page
  end
end
